<template>
  <div class="versionsOrder">
    <!-- 版本订单 -->
    <!-- 搜索筛选部分 -->
    <div class="search">
      <el-button
        size="small"
        style="visibility: hidden;border: none;color: #626366;font-size: 14px;background-color: #f1f1f1"
        @click="handleShow"
      >
        <i class="iconshalou"></i>高级查询
      </el-button>
      <div class="searInp">
        <el-input
          v-model="search"
          style="width: 250px"
          size="small"
          placeholder="输入订单号/商户账号/店铺id"
          clearable
          @keyup.enter.native="handleSearch"
        ></el-input>
        <el-button
          type="primary"
          @click="handleSearch"
          style="padding: 2px 15px;margin-left: 10px;border: none;color: #626366;background-color: #f1f1f1"
        >搜索</el-button>
      </div>
    </div>
    <!-- 订单统计 -->
    <Statistics :totalMoney="totalMoney" ></Statistics>
    <!-- 表格部分 -->
    <div class="tableData">
      <el-table style="width: 100%;margin-bottom: 40px" :data="tableData">
        <el-table-column align="center" label="序号" type="index" width="50"></el-table-column>
        <el-table-column align="center" min-width="90" label="订单号" prop="order_id"></el-table-column>
        <el-table-column align="center" min-width="120" label="店铺id">
          <template slot-scope="scope">
            <div class="contentToDraw">
              <span>{{ scope.row.user_id}}</span>
              <span v-if="scope.row.sv_salestype=='新'" class="dec">{{scope.row.sv_salestype}}</span>
              <span
                v-else-if="scope.row.sv_salestype=='续'"
                style="background: #ffa500"
                class="dec"
              >{{scope.row.sv_salestype}}</span>
              <span
                v-else="scope.row.sv_salestype=='升'"
                style="background: #67c23a"
                class="dec"
              >{{scope.row.sv_salestype}}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          min-width="100"
          show-overflow-tooltip
          label="店铺名称"
          prop="sv_us_name"
        ></el-table-column>
        <el-table-column align="center" min-width="120" label="商户账号" prop="sv_ul_acountno"></el-table-column>
        <el-table-column align="center" min-width="100" label="版本信息" prop="sv_do_content"></el-table-column>
        <el-table-column align="center" label="支付方式" prop="sv_paytype"></el-table-column>
        <el-table-column align="center" label="价格" prop="sv_do_price"></el-table-column>
        <el-table-column align="center" label="订单状态" prop="sv_dos_name">
          <template slot-scope="scope">
            <span
              :style="scope.row.sv_dos_name === '已付款' ? 'color: inherit' : 'color: #ff0000'"
            >{{scope.row.sv_dos_name}}</span>
          </template>
        </el-table-column>
        <el-table-column
          min-width="160"
          align="center"
          :formatter="dateFormat"
          label="付款时间"
          prop="sv_paymentdate"
        ></el-table-column>
      </el-table>
    </div>
    <!-- 分页器部分 -->
    <Pagination
      :total="total"
      :pageIndex="pageIndex"
      :pageSize="pageSize"
      @handleSizeChange="handleSizeChange"
      @handleCurrentChange="handleCurrentChange"
    ></Pagination>
  </div>
</template>

<script>
import Statistics from "@/components/Statistics";
import Pagination from "@/components/Pagination";
export default {
  data() {
    return {
      // 筛选的数据
      form: {
        status: "",
        payWay: "",
        versions: "",
        orderTime: "",
        payTime: ""
      },
      // 更改筛选框状态
      isShow: false,
      search: "",
      // 表格数据
      tableData: [],
      // 订单类型
      salestype: ["新", "续", "升"],
      // 总代币
      totalMoney: 0,
      // 分页器的数据
      total: 0, // 总条数
      pageIndex: 1, // 当前页
      pageSize: 10, // 每页数量
      // 身份令牌
      myToken: ""
    };
  },
  components: { Pagination, Statistics },
  methods: {
    init() {
      // 获取令牌
      this.myToken = sessionStorage.getItem("myToken");
      // 获取订单列表,初始化列表
      this.getOrderData();
    },
    // 获取列表数据的方法
    getOrderData() {
      this.$api
        .getVersionOrderData(
          this.pageIndex,
          this.pageSize,
          this.search.trim(),
          this.myToken
        )
        .then(res => {
          this.totalMoney = 0;
          this.total = res.total;
          if (!res.dataList) {
            this.tableData = res.dataList;
            return;
          }
          this.tableData = res.dataList.map(v => {
            // 订单类型
            if (v.sv_salestype == 0) {
              v.sv_salestype = this.salestype[0];
            } else if (v.sv_salestype == 1) {
              v.sv_salestype = this.salestype[1];
            } else {
              v.sv_salestype = this.salestype[2];
            }
            // 没有记录的时间显示为空
            if (v.sv_paymentdate.substring(0, 1) == "0") {
              v.sv_paymentdate = null;
            }
            this.totalMoney += v.sv_do_price;
            return {
              ...v,
              order_id: v.order_id.substring(v.order_id.length - 8)
            };
          });
        });
    },
    // 搜素的方法
    handleSearch() {
      this.pageIndex = 1;
      this.getOrderData();
    },
    // 切换筛选框状态
    handleShow() {
      this.isShow = !this.isShow;
    },
    handleFiltrate() {
      this.pageIndex = 1;
      this.getOrderData();
    },
    // 分页器的方法
    handleSizeChange(val) {
      this.pageSize = val;
      this.getOrderData();
    },
    handleCurrentChange(val) {
      this.pageIndex = val;
      this.getOrderData();
    },
    //时间格式化
    dateFormat: function(row, column) {
      var date = row[column.property];
      if (date == undefined) {
        return "";
      }
      return this.$moment(date).format("YYYY-MM-DD HH:mm:ss");
    }
  },
  mounted() {
    // 初始化函数
    this.init();
  }
};
</script>

<style lang="less" scoped>
@deep: ~">>>";
.versionsOrder {
  background-color: #fff;
  padding: 20px;
  .search {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
    .searInp {
      display: flex;
    }
  }
  .filtrate {
    padding: 5px 10px;
    background-color: #f1f1f1;
    .el-radio-button {
      margin-right: 10px;
    }
  }
  .tableData {
    .contentToDraw {
      .dec {
        background: #409eff;
        color: #fff;
        padding: 2px 8px;
      }
    }
  }
  // 表格表头
  .tableData @{deep} .el-table th {
    background-color: #fafafa;
    color: #252525;
    font-weight: 100;
  }
  // 筛选的每一项
  .filtrate @{deep} .el-form-item {
    margin-bottom: 0;
  }
  // 筛选项的标题
  .filtrate @{deep} .el-form-item__label {
    color: #000;
    font-weight: 600;
  }
  // 筛选项的内容
  .filtrate @{deep} .el-radio-button__inner {
    border: 1px solid #f1f1f1;
    background-color: #f1f1f1;
    font-size: 14px;
    color: #626366;
  }
  // 筛选项选中内容
  .filtrate @{deep} .is-active .el-radio-button__inner {
    background-color: #f1f1f1;
    border: 1px solid #439fff;
    box-shadow: unset;
    color: #666;
    border-radius: 4px;
  }
}
</style>